package com.taobao.yugong.translator;

import com.taobao.yugong.common.db.meta.ColumnMeta;
import com.taobao.yugong.common.db.meta.ColumnValue;
import com.taobao.yugong.common.model.record.Record;

import java.sql.Types;

/**
 * 一个迁移的例子，涵盖一些基本转换操作
 *
 * <pre>
 * 例子包含特性：
 * 1. schema/table名不同. oracle中为yugong_example_oracle，mysql中为test.yugong_example_mysql
 * 2. 字段名字不同.  oracle中的name字段，映射到mysql的display_name
 * 3. 字段逻辑处理.  mysql的display_name字段数据来源为oracle库的:name+'('alias_name+')'
 * 4. 字段类型不同.  oracle中的amount为number类型，映射到mysql的amount为varchar文本型
 * 5. 源库多一个字段. oracle中多了一个alias_name字段
 * 6. 目标库多了一个字段. mysql中多了一个gmt_move字段，(简单的用迁移时的当前时间进行填充)
 *
 * 测试的表结构：
 * // oracle表
 * create table yugong_example_oracle
 * (
 *     id NUMBER(11)  ,
 *     name varchar2(32) ,
 *     alias_name  char(32) default ' ' not null,
 *     amount number(11,2),
 *     score  number(20),
 *     text_b blob,
 *     text_c clob,
 *     gmt_create date not null,
 *     gmt_modified date not null,
 *     CONSTRAINT yugong_example_oracle_pk_id  PRIMARY   KEY (id)
 * );
 *
 * // mysql表
 * create table test.yugong_example_mysql
 * (
 *     id bigint(20) unsigned auto_increment,
 *     display_name varchar(128) ,
 *     amount varchar(32),
 *     score bigint(20) unsigned ,
 *     text_b blob,
 *     text_c text,
 *     gmt_create timestamp not null,
 *     gmt_modified timestamp not null,
 *     gmt_move timestamp not null,
 *     CONSTRAINT yugong_example_mysql_pk_id  PRIMARY KEY (id)
 * );
 * </pre>
 *
 * @author agapple 2013-10-10 下午3:28:33
 */
public class BzHouseNewDataTranslator extends AbstractDataTranslator implements DataTranslator {

    public boolean translator(Record record) {
        record.setSchemaName("hddp-order");
        record.setTableName("bz_house_new");

        record.removeColumnByName("OWNERSHIP_CODE");
        record.removeColumnByName("BUILDING_NO");
        record.removeColumnByName("UNIT");
        record.removeColumnByName("FLOOR_TOTAL");
        record.removeColumnByName("ROOM_NO");
        record.removeColumnByName("MAILBOX_NO");
        record.removeColumnByName("PROPERTY_ADDRESS");
        record.removeColumnByName("IS_EXCHANGE");
        record.removeColumnByName("FRAME_CODE");
        record.removeColumnByName("DISPOSE_FRAME_CODE");
        record.removeColumnByName("BUILD_SIZE");
        record.removeColumnByName("BUILDING_TYPE");
        record.removeColumnByName("PROPERTY_TYPE");
        record.removeColumnByName("ORIENTATION");
        record.removeColumnByName("USAGE_TYPE");
        record.removeColumnByName("FITMENT_CODE");
        record.removeColumnByName("SCENE");
        record.removeColumnByName("IS_ANEAR_SUBWAY");
        record.removeColumnByName("IS_SCHOOL_DISTRICT");
        record.removeColumnByName("UPDATED_TIME");
        record.removeColumnByName("HOMELINK_CITY");
        record.removeColumnByName("BATCH");
        record.removeColumnByName("RENT_STATUS");
        record.removeColumnByName("IS_STOCK");
        record.removeColumnByName("HOUSE_STATUS");
        record.removeColumnByName("BUILDING_FRAME");
        record.removeColumnByName("BIZCIRCLE_ID",true);
        record.removeColumnByName("LEGACY_HOUSE_ID");
        record.removeColumnByName("IS_SYNCH_TIME_BUILDING");
        record.removeColumnByName("NAME");
        record.removeColumnByName("LADDER_AMOUNT");
        record.removeColumnByName("FAMILY_AMOUNT");
        record.removeColumnByName("SUPPLY_HEAT");
        record.removeColumnByName("FEATURE");
        record.removeColumnByName("OTHER_INTRO");
        record.removeColumnByName("UNIT_PHOTO");
        record.removeColumnByName("IS_SCHEME");
        record.removeColumnByName("ZR_HOUSE_CODE");
        record.removeColumnByName("OWNER_ID_BAK");
        record.removeColumnByName("UNIT_PHOTO_DATE");
        record.removeColumnByName("AUDIT_STATE");
        record.removeColumnByName("LAST_MODIFY_TIME_SYNCHRONOUS");
        record.removeColumnByName("ARREARAGE_STATE");
        record.removeColumnByName("TERRITORY_CODE");
        record.removeColumnByName("IS_WAVE_WASH");
        record.removeColumnByName("PRE_HOUSE_TYPE");
        record.removeColumnByName("HOUSE_RATING");

        record.removeColumnByName("FLOOR");

        ColumnMeta newDataSyncDateMeta = new ColumnMeta("new_data_sync_date", Types.TIMESTAMP);
        ColumnValue newDataSyncDateColumn = new ColumnValue(newDataSyncDateMeta, null);
        newDataSyncDateColumn.setCheck(false);// 该字段不做对比
        record.addColumn(newDataSyncDateColumn);

        return super.translator(record);
    }
}
